package com.ruoyi.business.base.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.base.domain.AssetCard;
import com.ruoyi.business.base.mapper.AssetCardMapper;
import com.ruoyi.business.base.service.IAssetCardService;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.uuid.SnowIdUtil;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 资产档案Service业务层处理
 *
 * @author lcy
 * @date 2024-09-24
 */
@Service
public class AssetCardServiceImpl extends ServiceImpl<AssetCardMapper, AssetCard> implements IAssetCardService {

    @Resource
    private AssetCardMapper assetCardMapper;

    /**
     * 查询资产档案
     *
     * @param id 资产档案主键
     * @return 资产档案
     */
    @Override
    public AssetCard selectAssetCardById(String id) {
        return assetCardMapper.selectAssetCardById(id);
    }

    /**
     * 查询资产档案列表
     *
     * @param assetCard 资产档案
     * @return 资产档案
     */
    @Override
    public List<AssetCard> selectAssetCardList(AssetCard assetCard) {
        return assetCardMapper.selectAssetCardList(assetCard);
    }

    /**
     * 新增资产档案
     *
     * @param assetCard 资产档案
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor =  Exception.class)
    public Object insertAssetCard(AssetCard assetCard) {
        assetCard.setId(SnowIdUtil.genSnowId())
                    .setCreateBy(SecurityUtils.getUsername())
                    .setCreateTime(DateUtils.getNowDate())
                    .setUpdateBy(SecurityUtils.getUsername())
                    .setUpdateTime(DateUtils.getNowDate());
        assetCardMapper.insert(assetCard);
        return assetCard.getId();
    }

    /**
     * 修改资产档案
     *
     * @param assetCard 资产档案
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor =  Exception.class)
    public int updateAssetCard(AssetCard assetCard) {
        assetCard.setUpdateBy(SecurityUtils.getUsername())
                    .setUpdateTime(DateUtils.getNowDate());
        return assetCardMapper.updateById(assetCard);
    }

    /**
     * 批量删除资产档案
     *
     * @param ids 需要删除的资产档案主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor =  Exception.class)
    public int deleteAssetCardByIds(String[] ids) {
        return assetCardMapper.deleteAssetCardByIds(ids);
    }

}
